package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.City;
import com.ruoyi.logistic.domain.Province;
import com.ruoyi.logistic.service.ProvinceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/user/provinceCity")
@RestController
@Api(tags = "省市")
public class ProvinceCityController {
    @Autowired
    private ProvinceService provinceService;
    @ApiOperation("显示省份列表")
    @GetMapping("/province")
    public R selectProvince(){
        List<Province> provinceList = provinceService.selectAll();
        if (provinceList == null || provinceList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(provinceList);
        }
    }
    @ApiOperation("根据省份查询城市列表")
    @GetMapping("/selectByProvince")
    public R selectByProvince(Integer pid){
        List<City> cityList = provinceService.selectByProvince(pid);
        if (cityList == null || cityList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(cityList);
        }
    }
}
